package com.bjsxt.base.conn012;

import java.util.Iterator;
import java.util.Vector;

public class Tickets {
    public static void main(String[] args) {
        // 初始化火车票池并添加火车票，避免线程同步可采用 Vector 替代 ArrayList
        // HashTable 替代 HashMap
        final Vector<String> tickets = new Vector<>();
        for (int i = 1; i <= 1000; i++) {
            tickets.add("火车票" + i);
        }
//        for(Iterator iterator = tickets.iterator(); iterator.hasNext()) {
//            String str = (String) iterator.next();
//            tickets.remove(20);
//        }
        for(int i=1; i <= 10; i++) {
            new Thread("线程"+i){
                @Override
                public void run() {
                    while (true) {
                        if(tickets.isEmpty()) break;
                        System.out.println(Thread.currentThread().getName() + "---" + tickets.remove(0));
                    }
                }
            }.start();
        }
    }
}
